<?php
include "../../../lib/list.php";

if($_POST['mode']=='insert'){
$s_no 		=	 $_POST['s_no'];
$no 		=	 $_POST['chk_no'];
$admin_name	=	$_SESSION['IS_NAME'];
//for문 시작------------------------------------------------------------------>
for($i=0;$i<count($no);$i++){
		if(!$s_no){
		echo("
		    <script>
				      window.alert('잘못된 점포입니다.');
				      </script>");
		echo "<meta http-equiv='refresh' content='0; url=$referer_domain'>";
		return;
		}
		if(!$no[$i]){
		echo("
		    <script>
				      window.alert('잘못된 상품입니다.');
				      </script>");
				echo "<meta http-equiv='refresh' content='0; url=$referer_domain'>";
				return;
		}
		if(!$admin_name){
		echo("
			<script>
				      window.alert('잘못된 담당자입니다.');
				      </script>");
				echo "<meta http-equiv='refresh' content='0; url=$referer_domain'>";
			return;
		}
				else{	
				$list 				= DBarray("SELECT * FROM uatp_stocktmp WHERE no = $no[$i]");
				
 				$lastdate			= DBarray("SELECT * FROM `uatp_stockreview` WHERE p_no = $list[p_no] AND s_no = $list[s_no] ORDER BY date DESC LIMIT 0, 1");
				
				$stockreview		= "INSERT INTO `uatp_stockreview`
										(`s_no`, `admin_name`, `p_no`, `instock`, `defect`, `move`, `sale`, `nowstock`, `realstock`, `gap`, `date`,`lastdate`)
										VALUES 
										(%d, '%s', %d, %d, %d, %d, %d, %d, %d, %d, '%s', '%s');";
				
				$query = sprintf($stockreview
						,$list['s_no']
						,$admin_name
						,$list['p_no']
						,$list['instock']
						,$list['defect']
						,$list['move']
						,NULL
						,$list['nowstock']
						,$list['realstock']
						,$list['gap']
						,$list['date']
						,$lastdate['date']);
				
				DBquery($query);
				DBquery("DELETE FROM `uatp_stocktmp` WHERE no = $no[$i] LIMIT 1");
				}
}
//for문 종료------------------------------------------------------------------>
					
				mysql_close();
					
				MsgViewLo('정상 입력 됐습니다.','stview.php');
}